<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2021/5/1
  Time: 13:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="/js/jquery-1.11.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/js/etao.js"></script>
    <script type="text/javascript" src="/js/cart.js"></script>
    <link href="/css/etao.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/css/cart.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/css/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <title>订单确认 </title>
</head>
<body class="container">
<script type="text/javascript">
    $(document).ready(function() {
        $("#new_address_dialog").on("show.bs.modal", function (e) {
            loadPage("new_address_content_div", "<?php echo $this->baseUrl . '/system/address/add.ajax/cid/' . $this->customerId . '/from/' . base64_encode($_SERVER['REQUEST_URI']); ?>");
        });

        $("#new_address_dialog").on("hidden.bs.modal", function (e) {
            $(this).removeData("bs.modal");
        });

        $("#new_address_button").click(function() {
            $.ajax({
                url: "<?php echo $this->baseUrl . '/system/address/save.ajax' ?>",
                type: 'POST',
                data: {"customer":$('#customer').val(),"address":$('#address').val(),"zip_code":$('#zip_code').val(),"telephone":$('#telephone').val(),"cell_phone":$('#cell_phone').val(),"contact_person":$('#contact_person').val(),"province_name":$('#province_name').val(),"city_name":$('#city_name').val(),"area_name":$('#area_name').val(),"is_default":0},
                error: function() { alert("添加收货地址出错!!"); },
                success: function(msg) {
                    //alert(msg);
                    $(".address-list li").removeClass("selected");
                    $(".address-list").append("<li class='selected'><input type='radio' id='addr_0' name='ship_to1' value='' checked /><label for='addr_0'>" + msg + "</label>");
                    $('#ship_to').val(msg);
                    $("#new_address_dialog").modal("hide");
                }
            });
        });

        $(".address-list li :radio").click(function() {
            $(this).parent().parent().addClass("selected").siblings().removeClass("selected");
        });

        $("#rebate").blur(function() { //确保返利的数字有效
            item_qty = parseInt($(this).val());
            if (isNaN(item_qty) || (item_qty == 0)) {
                $(this).val($("#max_rebate").val());
            }
        });

        $("#credit").blur(function() { //确保信用额度的数字有效
            item_qty = parseInt($(this).val());
            if (isNaN(item_qty) || (item_qty == 0)) {
                $(this).val(0);
            }
        });

        $("#new_iris_project_dialog").on("show.bs.modal", function (e) {
            loadPage("new_iris_project_content_div", "<?php echo $this->baseUrl . '/trans/iris/add.ajax/'; ?>");
        });

        $("#new_iris_project_dialog").on("hidden.bs.modal", function (e) {
            $(this).removeData("bs.modal");
        });

        $("#new_iris_project_button").click(function() {
            $.ajax({
                url: "<?php echo $this->baseUrl . '/trans/iris/save.ajax' ?>",
                type: 'POST',
                data: {"db_action":$('#db_action').val(),"customer_id":$('#customer_id').val(),"project_name":$('#project_name').val(),"project_site":$('#project_site').val(),"project_cycle":$('#project_cycle').val(),"project_vendor":$('#project_vendor').val(),"freezing_medium":$('#freezing_medium').val(),"is_valid":$('#is_valid').val()},
                error: function() { alert("添加IRIS项目出错!!"); },
                success: function(msg) {
                    $("#new_iris_project_dialog").modal("hide");
                    location.reload();
                }
            });
        });
    });

    function saveAddress() {
        $.ajax({
            type: "post",
            url: "<?php echo $this->baseUrl . '/system/address/save.ajax';?>",
            data: {"customer":$('#customer').val(),"address":$('#address').val(),"zip_code":$('#zip_code').val(),"telephone":$('#telephone').val(),"cell_phone":$('#cell_phone').val(),"contact_person":$('#contact_person').val(),"province_name":$('#province_name').val(),"city_name":$('#city_name').val(),"area_name":$('#area_name').val(),"is_default":0},
            error: function(msg) {alert("Error:" + msg);},
            success: function(msg) {
                $(".address-list li").removeClass("selected");
                $(".address-list").append("<li class='selected'><input type='radio' id='addr_0' name='ship_to1' value='' checked /><label for='addr_0'>" + msg + "</label>");
                $('#ship_to').val(msg);
                closeDiv('new_address_div');
            }
        });
    }

    //数据检查
    function beforePost() {
        if (isValid() == false) return false;
        if (($("#BTB2").prop("checked") == true) && (jQuery.trim($('#BTB_desc').val()) == "")) {
            alert("请注明最终用户名称和最终目的地！");
            return false;
        }
        if ($("#use_rebate").prop("checked") == true) {
            if (parseInt($("#rebate").val()) > parseInt($("#max_rebate").val())) {
                //alert($("#rebate").val());
                //alert($("#max_rebate").val());
                alert("返利使用金额超出最大值");
                $("#rebate").focus();
                return false;
            }
        }
        if ($("#terms").prop("checked") == false) {
            alert("提交订单前，请阅读《花卉销售条款和条件》");
            return false;
        }
        return true;
    }
</script>


<div class="row">
    <div class="col-lg-2 col-md-2 col-sm-2 col-xs-3 hidden-print">
        LEFT MENU
    </div>

    <div class="col-lg-10 col-md-10 col-sm-10 col-xs-9" id="workspace" role="main">

        <div class="row hidden-print">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <ol class="breadcrumb">
                    <li><a href="<%=application.getContextPath()%>">首页</a></li>
                    <li class="active">确认购买</li>
                </ol>
            </div>
        </div>

        <form style="margin-bottom:40px;" class="form-horizontal" id="order_confirm_form"
              name="order_confirm_form" method="POST"
              action="<%=application.getContextPath()%>/cart/jump">
            <input type="hidden" id="db_action" name="db_action" value="insert" />
            <input type="hidden" id="freight_fee" name="freight_fee" value="0" />

            <!-- 订单信息 -->
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="well well-sm">
                            <legend>订单信息</legend>
                            <div class="form-group">
                                <label
                                        class="col-lg-2 col-md-2 col-sm-2 col-xs-12 control-label"
                                        for="customer_PO_num">客户订单号</label>
                                <div class="col-lg-10 col-md-10 col-sm-10 col-xs-12">
                                    <input class="form-control input-sm" id="customer_PO_num"
                                           name="customer_PO_num" required requireText="请输入客户订单号"
                                           type="text" maxLength="50" value="${allmoney}" autofocus />
                                    <p class="help-block">
                                        请确保该订单号在当前<abbr title="艾默生为经销商分配的唯一代码">客户代码</abbr>下是唯一的
                                    </p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label
                                        class="col-lg-2 col-md-2 col-sm-2 col-xs-12 control-label"
                                        for="payment_term">付款方式</label>
                                <div class="col-lg-10 col-md-10 col-sm-10 col-xs-12">
                                    <select class="form-control input-sm" id="payment_term"
                                            name="payment_term" required requireText="请选择付款方式">
                                        <option value="zfb">支付宝</option>
                                        <option value="vx">微信</option>
                                        <option value="card">银行卡</option>
                                    </select>
                                </div>
                            </div>
                    </div>
                </div>
            </div>

            <!-- 收货地址 -->
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="well well-sm">
                        <fieldset>
                            <legend>
                                收货地址
                                <div class="btn-toolbar pull-right hidden-print" role="tolbar">
                                    <div class="btn-group btn-group-sm">
                                        <button type="button" class="btn btn-default"
                                                title="添加并使用新的收货地址" data-toggle="modal"
                                                data-target="#new_address_dialog">使用新地址</button>
                                    </div>
                                </div>
                            </legend>
                            <div class="form-group">
                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                    <div class="address">
                                        <ul class="address-list data-list">
                                            <li><label><input type="radio" name="ship_to1"
                                                              onclick="$('#ship_to').val($(this).parent().text());" />${useraddress}</label>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </div>
            </div>


            <div class="row">
                <div
                        class="col-lg-offset-3 col-md-offset-3 col-sm-offset-3 col-lg-6 col-md-6 col-sm-6 col-xs-12">
                    <button type="button" class="btn btn-lg btn-block btn-primary"
                            id="btn_submit_order"
                            onclick="order_confirm_form.submit();">提交订单</button>
                </div>
            </div>
        </form>
    </div>
    <!-- 添加收货地址模式窗体 -->
    <div class="modal fade" role="dialog" tabIndex="-1"
         id="new_address_dialog" aria-labelledby="new_address_modal_label"
         aria-hidden="true" data-backdrop="static">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body" id="new_address_content_div"></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary"
                            id="new_address_button">保存并使用</button>
                </div>
            </div>
        </div>
    </div>


</div>
</body>
</html>